package cn.edu.nju.ws.sview.reasoning.magicsets;

import java.util.Arrays;

import cn.edu.nju.ws.sview.rdf.Resource;
import cn.edu.nju.ws.sview.reasoning.Predicate;

/**
 * @author Gong Saisai
 *magicsets AdornedPredicate  
 * 
 */
public class AdornedPredicate extends Predicate{
    private BoundFree[] adornment;

	public AdornedPredicate(Predicate predicate, final BoundFree[] adornment) {
		super(predicate);
		this.adornment = new BoundFree[adornment.length];
		for (int i = 0; i < adornment.length; i++) {
			this.adornment[i] = adornment[i];
		}
	}

	public AdornedPredicate(final Resource resource, int arity,
			final BoundFree[] adornment) {
		super(resource, arity);
		this.adornment = new BoundFree[adornment.length];
		for (int i = 0; i < adornment.length; i++) {
			this.adornment[i] = adornment[i];
		}
	}

	public Predicate getPred() {
		return new Predicate(this.getResource(), this.getArity());
	}

	public BoundFree[] getAdornment() {
		return this.adornment;
	}

	public int getBoundArgNum() {
		int count = 0;
		for (int i = 0; i < adornment.length; i++) {
			if (adornment[i] == BoundFree.BOUND)
				count++;
		}
		return count;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + Arrays.hashCode(adornment);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		AdornedPredicate other = (AdornedPredicate) obj;
		if (!Arrays.equals(adornment, other.adornment))
			return false;
		return true;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.toString() + "^");
		for (int i = 0; i < this.adornment.length; i++) {
			sb.append(adornment[i]);
		}
		return sb.toString();
	}
}
